package com.instpower.things.instpower;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

/**
 * @ClassName Context
 * @Author: hellmash@gmail.com
 * @Date: 2020/2/24
 * @Version: 1.0.0
 * @Description: TODO
 */
public class Context {
    private final ApplicationContext applicationContext;

    private final static Context context = new Context();

    private Context() {
        applicationContext = new ClassPathXmlApplicationContext("classpath:ApplicationContext.xml");
    }

    public static <T> T getBean(Class<T> clazz) {
        return context.applicationContext.getBean(clazz);
    }

    public static <T> T getBean(String name) {
        return (T) context.applicationContext.getBean(name);
    }

    public static <T> Map<String, T> getBeansOfType(Class<T> type) {
        return context.applicationContext.getBeansOfType(type);
    }

}
